package com.ruoyi.system.service.impl;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.entity.SafetyInstrument;
import com.ruoyi.system.mapper.SafetyInstrumentMapper;
import com.ruoyi.system.service.SafetyInstrumentService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * 安全仪表基础点位信息(SafetyInstrument)表服务实现类
 * @since 2023-04-21 14:59:48
 */
@Service("safetyInstrumentService")
public class SafetyInstrumentServiceImpl implements SafetyInstrumentService {
    @Resource
    private SafetyInstrumentMapper safetyInstrumentDao;

    /**
     * 通过ID查询单条数据
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public SafetyInstrument queryById(Integer id) {
        return this.safetyInstrumentDao.queryById(id);
    }

    /**
     * 分页查询
     * @return 查询结果
     */
    @Override
    public List<SafetyInstrument> queryByPage(SafetyInstrument safetyInstrument) {
        return safetyInstrumentDao.queryAllByLimit(safetyInstrument);
    }

    /**
     * 新增数据
     * @param safetyInstrument 实例对象
     * @return 实例对象
     */
    @Override
    public SafetyInstrument insert(SafetyInstrument safetyInstrument) {
        safetyInstrument.setCreateTime(DateUtils.getNowDate());
        this.safetyInstrumentDao.insert(safetyInstrument);
        return safetyInstrument;
    }

    /**
     * 修改数据
     * @param safetyInstrument 实例对象
     * @return 实例对象
     */
    @Override
    public SafetyInstrument update(SafetyInstrument safetyInstrument) {
        safetyInstrument.setUpdateTime(DateUtils.getNowDate());
        this.safetyInstrumentDao.update(safetyInstrument);
        return this.queryById(safetyInstrument.getId());
    }

    /**
     * 通过主键删除数据
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.safetyInstrumentDao.deleteById(id) > 0;
    }

    /**
     *
     * @param safetyInstruments
     * @param updateSupport
     * @param operName
     * @return
     */
    @Override
    public String importExcel(List<SafetyInstrument> safetyInstruments, boolean updateSupport, String operName) {
        if (StringUtils.isNull(safetyInstruments) || safetyInstruments.size() == 0) {
            throw new ServiceException("导入用户数据不能为空！");
        }
        safetyInstrumentDao.insertBatch(safetyInstruments);
        return "成功";
    }
}
